package com.ch.pagedemo.viewmodel

import androidx.lifecycle.LiveData
import androidx.lifecycle.ViewModel
import androidx.paging.LivePagedListBuilder
import androidx.paging.PagedList
import com.ch.pagedemo.pading.MovieDataSourceFactory
import com.ch.pagedemo.bean.Movie as Movie1

class MovieViewModel : ViewModel() {

    var moviePagedList: LiveData<PagedList<Movie1>>? = null

    init {
        val config = PagedList.Config.Builder()
            //设置控件占位
            .setEnablePlaceholders(false)
            .setPageSize(10)
            //设置距离底部多少条加载下一页
            .setPrefetchDistance(1)
            //设置首次加载的数量
            .setInitialLoadSizeHint(10 * 2)
            .setMaxSize(65536 * 10)
            .build()
        moviePagedList = LivePagedListBuilder(
            MovieDataSourceFactory(), config
        ).build()
    }
}